# -*- coding: utf-8 -*-
# @Time    : 2018/12/23/023 21:29
# @Author  : 山那边的瘦子
# @Email   : 690238539@qq.com
# @File    : apps.py

from flask import Flask
from config import Config
from exts import mongo
from models import IPS
from utils import restful

from tasks import get_ips

app = Flask(__name__)

app.config.from_object(Config)
mongo.init_app(app)
get_ips.delay()


@app.route('/')
def default():
    return '/'


@app.route('/api/v1.0/ips/', methods=['GET', 'POST'])
def ips():
    ips = IPS.objects.all()
    tmp_ips = list()
    for ip in ips:
        tmp_ip = dict()
        tmp_ip['ip'] = ip.ip
        tmp_ip['type'] = ip.type
        tmp_ip['port'] = ip.port
        tmp_ip['survival'] = ip.survival
        tmp_ips.append(tmp_ip)
    return restful.success('/api/v1.0/ips/ , 请求成功!', data=tmp_ips)


if __name__ == '__main__':
    app.run()
